import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    // redirect: '/homepage',
    component: () => import('../views/index/index.vue'),
    children: [
      {
        path: 'role',
        component: () => import('../views/homeChildren/role.vue')
      },
      {
        path: 'user',
        component: () => import('../views/homeChildren/user.vue')
      },
      {
        path: 'menu',
        component: () => import('../views/homeChildren/menu.vue')
      },
      {
        path: 'category',
        component: () => import('../views/homeChildren/category.vue')
      },
      {
        path: 'specs',
        component: () => import('../views/homeChildren/specs.vue')
      },
      {
        path: 'goods',
        component: () => import('../views/homeChildren/goods.vue')
      },
      {
        path: 'member',
        component: () => import('../views/homeChildren/member.vue')
      },
      {
        path: 'banner',
        component: () => import('../views/homeChildren/banner.vue')
      },
      {
        path: 'seckill',
        component: () => import('../views/homeChildren/seckill.vue')
      },
      {
        path: 'orders',
        component: () => import('../views/homeChildren/orders.vue')
      },
      {
        path: 'ceshi', 
        component: () => import('../views/homeChildren/ceshi.vue')
      },
      {
        path: 'deded',
        component: () => import('../views/homeChildren/deded.vue')
      },
    ]
  },
  {
    path: '/login',
    component: () => import('../views/login/index.vue')
  },
]


const router = new VueRouter({
  routes
})

router.beforeEach((to,form,next)=>{
  let loca   = localStorage.getItem('userInfo')||""
  if(loca == '' && to.fullPath != '/login'){
    next('/login')
  }else {
    next()
  }
})
export default router
